<template>
  <div>
    <div class="content">
      <div class="return" @click="close">
        <img class="img1" src="../../assets/img/return.png" alt="" />
        <p class="return-p">返回</p>
      </div>
      <div class="card1" v-for="(item, index) in list" :key="index">
        <div class="flex">
          <div class="card1-text" style="flex: 1;">商户名：</div>
          <div class="card1-text">{{ item.name }}</div>
        </div>
        
        <div class="flex">
          <div class="card1-text" style="flex: 1;">申请时间：</div>
          <div class="card1-text">{{ item.starttime }}</div>
        </div>
        <div class="flex">
          <div class="card1-text" style="flex: 1;">提现订单金额：</div>
          <div class="card1-text" style="color: red;">{{ item.money+'元' }}</div>
        </div>
        <div class="flex">
          <div class="card1-text" style="flex: 1;">处理状态：</div>
          <div class="card1-text">{{ item.state == 1 ? '已提交 '  : item.state == 2 ? '已完成'  :  item.state == 3  ?  '失败' :  ''}}</div>
        </div>
       <!--  <div class="flex">
          <div class="card1-text" style="flex: 1;">处理时间：</div>
          <div class="card1-text">{{ item.endtime }}</div>
        </div> -->
        <div class="btn" v-if="item.state == 1 && cashType == 2">
          <div class="btn2" @click="btn5(item)">拒绝提现</div>
          <div class="btn1" @click="btn4(item)">同意提现</div>   
        </div>
      </div>
      <div class="norecords" v-if="list && list.length == 0">
        暂无记录
      </div>
    </div>
  </div>
</template>

<script>
import {withdrawList ,withdraw} from "@/api/fulfil.js";
export default {
  name:'cash',
  data() {
    return {
      agentid: "",
      list: [],
      role: "",
      cashType:'',
    };
  },
  mounted() {
   
    /* this.role = localStorage.getItem("role");
    this.getIndex(); */
  },
  activated() {
    this.cashType =  localStorage.getItem('cashType');
    this.role = localStorage.getItem("role");
    this.getIndex();
  },
  methods: {
    //列表数据
    getIndex() {
      withdrawList({
        adminid:localStorage.getItem("agentids"),
      })
        .then((res) => {
          this.list = res.data.data;
          console.log(res,'res');
        })
        .catch((error) => {
          console.log(error);
        });
    },
    //同意提现
    btn4(item){
      this.$dialog.confirm({
                title: '温馨提示',
                message: '您确定要同意该商户提现吗？',
            })
                .then(() => {
                    withdraw({
                        agentid: localStorage.getItem("agentids"),
                        id:item.id,
                        state:'2'
                    })
                        .then((res) => {
                            if (res.data.code == 0) {
                                this.$Toast("已同意该商户提现！");
                                this.getIndex();
                            } else {
                                this.$Toast(res.data.msg);
                            }
                        })
                        .catch((error) => {
                            console.log(error);
                        });
                })
                .catch(() => {
                    // on cancel
                });
    },
    //拒绝提现
    btn5(item){
      this.$dialog.confirm({
                title: '温馨提示',
                message: '您确定要拒绝该商户提现吗？',
            })
                .then(() => {
                    withdraw({
                        agentid: localStorage.getItem("agentids"),
                        id:item.id,
                        state:'3'
                    })
                        .then((res) => {
                            if (res.data.code == 0) {
                                this.$Toast("已拒绝该商户提现！");
                                this.getIndex();
                            } else {
                                this.$Toast(res.data.msg);
                            }
                        })
                        .catch((error) => {
                            console.log(error);
                        });
                })
                .catch(() => {
                    // on cancel
                });
    },
    close() {
      window.history.go(-1);
    },
  },
};
</script>

<style scoped>
.content {
  padding-bottom: 0.3rem;
  overflow: hidden;
  width: 100%;
  min-height: 100vh;
  background: #e1f7fc;
}
.card1 {
  overflow: hidden;
  margin: 0.3rem auto 0;
  padding: 0 0.5rem 0.25rem ;
  width: 84%;
  background: #fff;
  border-radius: 0.375rem;
  box-sizing: border-box;
}
.card1-title {
  margin-top: 0.2rem;
  font-size: 0.4125rem;
  font-weight: 600;
  color: #000;
}
.card1-text {
  margin: 0.25rem 0 0 0.2rem;
  font-size: 0.3125rem;
  font-weight: 600;
  color: #000;
}
.card1-text1 {
  margin: 0.25rem 0 0 0.2rem;
  font-size: 0.3125rem;
  font-weight: 600;
  color: #000;
  text-align: center;
}
.img1 {
  display: inline-block;
  width: 27px;
  height: 48px;
  vertical-align: middle;
}
.flex {
  display: flex;
}
.return {
  margin: 20px 0 0 30px;
  font-size: 40px;
}
.return-p {
  margin-left: 20px;
  display: inline-block;
  vertical-align: middle;
}
.norecords {
  margin-top: 2rem;
  color: #ffbe4c;
  font-size: .5rem;
  text-align: center;
}
.btn {
  margin-top: 0.6rem;
  display: flex;
  /* 应用Flex布局 */
  justify-content: space-between;
  /* 控制盒子之间的对齐方式 */
}

.btn1 {
  width: 30%;
  padding: 0 .3rem;
  height: 0.75rem;
  color: #fff;
  text-align: center;
  line-height: 0.75rem;
  border-radius: 0.375rem;
  background-color: #ffbe4c;
}
.btn2 {
  width: 30%;
  padding: 0 .3rem;
  height: 0.75rem;
  line-height: 0.75rem;
  text-align: center;
  color: #fff;
  border-radius: 0.375rem;
  background-color: red;
}

</style>